//
//  UserModel.m
//  itboye_jsq_ios
//
//  Created by Rajon on 15/12/5.
//  Copyright © 2015年 itboye. All rights reserved.
//

#import "UserModel.h"

@implementation UserModel




// 初始化方法，设置一些默认值
- (instancetype)init {
    
    self = [super init];
    if (self) {
        // 设置默认值
        [self defaultSettings];
    }
    return self;
}


// 初始化方法，设置一些默认值
- (instancetype)initContentWithDic:(NSDictionary *)jsonDic {
    
    self = [super initContentWithDic:jsonDic];
    if (self) {
        // 设置默认值
        [self defaultSettings];
    }
    return self;
}



// 设置默认值
- (void)defaultSettings {
    // 用户名
    if (_username == nil) {
        self.username = @"18888888888";
    }
    
    // 密码
    if (_password == nil) {
        self.password = @"";
    }
    
    // 性别
    if (_sex == nil) {
        self.sex = @"0";
    }
    
    // 邮箱
    if (self.email == nil) {
        self.email = @"";
    }
    
    // 用户ID
    if (self.uid == nil) {
        self.uid = @"";
    }
    
    // 头像
    if (self.head == nil) {
        self.head = @"";
    }
    
    // 故障推送开关
    if (self.error_tip == nil) {
        self.error_tip = @"0";
    }
    
    // 滤芯更换提醒
    if (self.change_tip == nil) {
        self.change_tip = @"0";
    }
    
    // 昵称
    if (self.nickname == nil) {
        self.nickname = @"0";
    }
    
    //手机号
    if (self.mobile == nil) {
        self.mobile = @"";
    }
    
    if (self.allowstickthread == nil) {
        self.allowstickthread = @"0";
    }
    
    if (self.allowdigestthread == nil) {
        self.allowdigestthread =@"0";
    }
    
    if (self.allowdelpost == nil) {
        self.allowdelpost = @"0";
    }
    
    if (self.fid == nil) {
        self.fid = @"";
    }
    
    if (self.allowpost == nil) {
        self.allowpost = @"1";
    }

}



// 获取model的字典形式
- (NSMutableDictionary *)getDictionary {
    
    NSMutableDictionary * userDic = [[NSMutableDictionary alloc] init];
    // 用户名
    if (self.username != nil && self.username.length > 0){
        [userDic setObject:self.username forKey:@"username"];
    }
    // 密码
    if (self.password != nil && self.password.length > 0){
        [userDic setObject:self.password forKey:@"password"];
    }
    // 性别
    if (self.sex != nil && self.sex.length > 0){
        [userDic setObject:self.sex forKey:@"sex"];
    }
    // 邮箱
    if (self.email != nil && self.email.length > 0){
        [userDic setObject:self.email forKey:@"email"];
    }
    // uid
    if (self.uid != nil && self.uid.length > 0){
        [userDic setObject:self.uid forKey:@"uid"];
    }
    // 头像
    if (self.head != nil && self.head.length > 0) {
        [userDic setObject:self.head forKey:@"head"];
    }
    // 故障推送开关
    if (self.error_tip != nil && self.error_tip.length > 0) {
        [userDic setObject:self.error_tip forKey:@"error_tip"];
    }
    // 滤芯更换提醒
    if (self.change_tip != nil && self.change_tip.length > 0) {
        [userDic setObject:self.change_tip forKey:@"change_tip"];
    }
    // 昵称
    if (self.nickname != nil && self.nickname.length > 0) {
        [userDic setObject:self.nickname forKey:@"nickname"];
    }
    //手机号
    if (self.mobile != nil && self.mobile.length > 0) {
        [userDic setObject:self.mobile forKey:@"mobile"];
    }
    //微信绑定码
    if (self.wxopenid != nil && self.wxopenid.length > 0) {
        [userDic setObject:self.wxopenid forKey:@"wxopenid"];
    }
    //微信登录标识
    if (self.reg_from != nil && self.reg_from.length > 0) {
        [userDic setObject:self.reg_from forKey:@"reg_from"];
    }
    if (self.allowdelpost != nil && self.allowdelpost.length > 0) {
        [userDic setObject:self.allowdelpost forKey:@"allowdelpost"];
    }
    if (self.allowstickthread != nil && self.allowstickthread.length > 0) {
        [userDic setObject:self.allowstickthread forKey:@"allowstickthread"];
    }
    if (self.allowdigestthread != nil && self.allowdigestthread.length > 0) {
        [userDic setObject:self.allowdigestthread forKey:@"allowdigestthread"];
    }
    
    if (self.fid != nil && self.fid.length > 0) {
        [userDic setObject:self.fid forKey:@"fid"];
    }
    
    if (self.allowpost != nil && self.allowpost.length > 0) {
        [userDic setObject:self.allowpost forKey:@"allowpost"];
    }

    
    
    return  userDic;
}



- (void)encodeWithCoder:(NSCoder *)aCoder {
    // 用户名
    [aCoder encodeObject:self.username forKey:@"username"];
    // 密码
    [aCoder encodeObject:self.password forKey:@"password"];
    // 性别
    [aCoder encodeObject:self.sex forKey:@"sex"];
    // 邮箱
    [aCoder encodeObject:self.email forKey:@"email"];
    // uid
    [aCoder encodeObject:self.uid forKey:@"uid"];
    // 头像
    [aCoder encodeObject:self.head forKey:@"head"];
    // 故障推送开关
    [aCoder encodeObject:self.error_tip forKey:@"error_tip"];
    // 滤芯更换提醒
    [aCoder encodeObject:self.change_tip forKey:@"change_tip"];
    // 昵称
    [aCoder encodeObject:self.nickname forKey:@"nickname"];
    //手机号
    [aCoder encodeObject:self.mobile forKey:@"mobile"];
    
    [aCoder encodeObject:self.wxopenid forKey:@"wxopenid"];
    
    [aCoder encodeObject:self.reg_from forKey:@"reg_from"];
    
    [aCoder encodeObject:self.allowdelpost forKey:@"allowdelpost"];
    
    [aCoder encodeObject:self.allowstickthread forKey:@"allowstickthread"];
    
    [aCoder encodeObject:self.allowdigestthread forKey:@"allowdigestthread"];
    
    [aCoder encodeObject:self.allowpost forKey:@"allowpost"];
    
    [aCoder encodeObject:self.fid forKey:@"fid"];
}


- (id)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super init]) {
        // 用户名
        self.username = [aDecoder decodeObjectForKey:@"username"];
        // 密码
        self.password = [aDecoder decodeObjectForKey:@"password"];
        // 性别
        self.sex = [aDecoder decodeObjectForKey:@"sex"];
        // 邮箱
        self.email = [aDecoder decodeObjectForKey:@"email"];
        // uid
        self.uid = [aDecoder decodeObjectForKey:@"uid"];
        // 头像
        self.head = [aDecoder decodeObjectForKey:@"head"];
        // 故障推送开关
        self.error_tip = [aDecoder decodeObjectForKey:@"error_tip"];
        // 滤芯更换提醒
        self.change_tip = [aDecoder decodeObjectForKey:@"change_tip"];
        
        self.mobile = [aDecoder decodeObjectForKey:@"mobile"];
        // 昵称
        self.nickname = [aDecoder decodeObjectForKey:@"nickname"];
        // 手机号
        self.wxopenid = [aDecoder decodeObjectForKey:@"wxopenid"];
        
        self.reg_from = [aDecoder decodeObjectForKey:@"reg_from"];
        
        self.allowdelpost = [aDecoder decodeObjectForKey:@"allowdelpost"];
        
        self.allowdigestthread = [aDecoder decodeObjectForKey:@"allowdigestthread"];
        
        self.allowstickthread = [aDecoder decodeObjectForKey:@"allowstickthread"];
        
        self.allowpost = [aDecoder decodeObjectForKey:@"allowpost"];
        
        self.fid = [aDecoder decodeObjectForKey:@"fid"];
    }
    return self;
}



-(NSString *)description {
    return [NSString stringWithFormat:@"username = %@ \n password = %@ \n sex = %@ \n email = %@ \n uid = %@ \n head = %@ \n error_tip = %@ \n change_tip = %@ \n mobile = %@",self.username,self.password,self.sex,self.email,self.uid,self.head,self.error_tip,self.change_tip,self.mobile
            ];
}



@end
